import csv


# 假设CSV文件的格式是固定的，并且每个参数有固定的数据类型
# 例如: Name(string), Age(int), IsStudent(bool)

# 生成C#属性的函数
def generate_csharp_property(data_type, name):
    # 根据数据类型转换为C#中的类型
    csharp_type = {
        'string': 'string',
        'int': 'int',
        'bool': 'bool'
    }.get(data_type, 'object')  # 默认为object类型

    return f"public {csharp_type} {name} {{ get; set; }}\n"


# 读取CSV文件并分析数据
def process_csv_to_csharp(csv_file_path, csharp_file_path):
    properties = []

    with open(csv_file_path, newline='') as csvfile:
        reader = csv.reader(csvfile)
        for row in reader:
            # 假设第一行是列名和类型（例如：Name(string), Age(int), IsStudent(bool)）
            if reader.line_num == 1:
                for column in row:
                    name, data_type = column.split('(')
                    data_type = data_type.rstrip(')')
                    property_definition = generate_csharp_property(data_type, name)
                    properties.append(property_definition)
            # 其他行可以进行其他分析，根据需要处理
            # ...

    # 将生成的C#代码写入文件
    with open(csharp_file_path, 'w') as csharp_file:
        csharp_file.writelines(properties)
if __name__ == '__main__':
    csv_file_path = 'D:\\pros\\vs\\ChipAssistant\\Document\\TMI85303寄存器汇总.csv'  # CSV文件路径
    csharp_file_path = 'Properties.cs'  # 生成的C#文件路径

    process_csv_to_csharp(csv_file_path, csharp_file_path)

